package de.koller.worlders.engine.util.thread;

public class VThreadTest implements IVThread {

	private ValueThread valueThread = ValueThread.create( new Something(), this );
	
	@Override
	public void handleThread() {
		System.out.println( "ReadyResource calc" );
		try { Thread.sleep( 1000 ); } catch( InterruptedException ex ) {}
	}
	
	private void init() {
		valueThread.startCalculateAsync();
	}

	private void update() {
		System.out.println( "|" );
		valueThread.calculateReadyWhenReady();
		valueThread.startCalculateAsync();
	}
	
	public static void main( String[] args ) {
		VThreadTest vtt = new VThreadTest();
		vtt.init();
		while( true ) {
			vtt.update();
			try { Thread.sleep( 250 ); } catch( InterruptedException ex ) {}
		}
	}
	
	private static class Something implements IVThread {

		@Override
		public void handleThread() {
			System.out.println( "Start something" );
			try { Thread.sleep( 3000 ); } catch( InterruptedException ex ) {}
			System.out.println( "End something" );
		}
		
	}
	
}
